
*****************
* R's Siblings *
*****************

*# of siblings  
    gen R_num_siblings = v734 if v734<.
    tab R_num_siblings, m
    label var R_num_siblings "# of R's siblings"
    
*# brothers--not available
*# sisters--not available

*********************
* R's Own fertility *
*********************

* # (living) boys--two parts: bio male kids and non-bio male kids
    //bio male kids: v268
    
    //non-bio male kids: v271-v278  
    foreach num of numlist 271/278 {
        if `num'==271 local i 1
        if `num'==272 local i 2
        if `num'==273 local i 3
        if `num'==274 local i 4
        if `num'==275 local i 5
        if `num'==276 local i 6
        if `num'==277 local i 7
        if `num'==278 local i 8 
        
        tab v`num',m 
        gen nonbiokid`i'_boy = (v`num'==1) if v`num'<.
        tab nonbiokid`i'_boy,m 
        
        tab v`num',m 
        gen nonbiokid`i'_girl = (v`num'==2) if v`num'<.
        tab nonbiokid`i'_girl, m 
        
    }
    
    egen R_num_nonbioboys = rowtotal(*_boy), missing

    gen R_num_boys_living = v268 /*biological male kids*/ + R_num_nonbioboys 
    tab R_num_boys_living, m //note: "8" is actually 8+. Coded as 8 to be conservative
    label var R_num_boys_living "# of R's living male children"

*Flag indeterminate (high) # of (bio) boys
    gen flag_8plusboys = (v268==8) if v268<.
    tab flag_8plusboys, m
    label var flag_8plusboys "Flag =1 if R has an indeterminate (8+) # of boys"
    
* # (living) girls--two parts: bio female kids and non-bio female kids
    //bio female kids: v269
    //non-bio female kids: v271-v278
    egen R_num_nonbiogirls = rowtotal(*_girl), missing      

    gen R_num_girls_living = v269 + R_num_nonbiogirls
    tab R_num_girls_living, m //note: "6" is actually 6+. Coded as 6 to be conservative
    label var R_num_girls_living "# of R's living female children"

*Flag indeterminate (high) # of (bio) girls
    gen flag_8plusgirls = (v269==8) if v269<.
    tab flag_8plusgirls, m
    label var flag_8plusgirls "Flag =1 if R has an indeterminate (8+) # of girls"

* # of living kids
    gen R_numkids_living =.
    replace R_numkids_living = R_num_girls_living + R_num_boys_living 
    tab R_numkids_living, m 
    label var R_numkids_living "# of R's kids who are living"

* # of deceased kids

    foreach num of numlist 258/267 {
        if `num'==258 local i 1
        if `num'==259 local i 2
        if `num'==260 local i 3
        if `num'==261 local i 4
        if `num'==262 local i 5
        if `num'==263 local i 6
        if `num'==264 local i 7
        if `num'==265 local i 8
        if `num'==266 local i 9
        if `num'==267 local i 10
    
        gen dead_biokid`i' = v`num'==3 if v`num'<.
        tab v`num', m
        tab dead_biokid`i', m
        
        //generate dummies for whether bio kid lives w/ R (will need later on)
        gen liveswR_biokid`i' = v`num'==1 if v`num'<.
        tab v`num',m 
        tab liveswR_biokid`i',m 
    }
    
        foreach num of numlist 287/294  {
        if `num'==287 local i 1
        if `num'==288 local i 2
        if `num'==289 local i 3
        if `num'==290 local i 4
        if `num'==291 local i 5
        if `num'==292 local i 6
        if `num'==293 local i 7
        if `num'==294 local i 8
    
        gen dead_nonbiokid`i' = v`num'==3 if v`num'<.
        tab v`num', m
        tab dead_nonbiokid`i', m

        //generate dummies for whether non-bio kid lives w/ R (will need later on)
        gen liveswR_nonbiokid`i' = v`num'==1 if v`num'<.
        tab v`num',m 
        tab liveswR_nonbiokid`i',m 

    }

    egen R_numbiokids_dead = rowtotal(dead_biokid*), missing 
    egen R_numnonbiokids_dead = rowtotal(dead_nonbiokid*), missing 
    
    gen R_numkids_dead = R_numbiokids_dead + R_numnonbiokids_dead 
    tab R_numkids_dead, m
    label var R_numkids_dead "# of R's kids who are deceased"
    
* # of kids ever (i.e., living + deceased)
    gen R_numkids_ever =. 
    replace R_numkids_ever = R_numkids_living + R_numkids_dead 
    tab R_numkids_ever, m
    label var R_numkids_ever "# of kids that R has ever had (living or deceased)"

* Dummy: has R ever had kids
    gen R_kids_ever = R_numkids_ever!=0 if R_numkids_ever<.
    tab R_kids_ever,m 
    label var R_kids_ever "Dummy=1 if R has ever had kids"

*Dummy: does R have kids right now (i.e. if no, then R either has never had kids or num kids living is 0)
    gen R_kids_now = R_numkids_living!=0 if R_numkids_living<. 
    tab R_kids_now,m 

*********************************
* # of persons in R's household *
*********************************

* # of children 0-17 living in R's hh
    ren v814 R_totnumkids_0to17_livinginhh
    tab R_totnumkids_0to17_livinginhh, m
    label var R_totnumkids_0to17_livinginhh "Total # of kids (0-17) living in R's hh"
    
********************************
********************************

* # of kids (of any age) living in R's hh
    
    //Step 1: generate dummies for whether each of R's bio and non-bio kids are 18+ in age  
    foreach num of numlist 248/257 279/286 {
        if `num'==248 | `num'==279 local i 1
        if `num'==249 | `num'==280 local i 2
        if `num'==250 | `num'==281 local i 3
        if `num'==251 | `num'==282 local i 4
        if `num'==252 | `num'==283 local i 5
        if `num'==253 | `num'==284 local i 6
        if `num'==254 | `num'==285 local i 7
        if `num'==255 | `num'==286 local i 8
        
        if `num'==256 local i 9 
        if `num'==257 local i 10
        
        if inrange(`num',248,257) local name bio
        if inrange(`num',279,286) local name nonbio 
    
        gen adult_`name'kid`i' = v`num'>=18 if v`num'<.
        tab v`num', m
        tab adult_`name'kid`i', m       
    }   
    
    //Step 2: create a dummy =1 if child is 18+ AND lives in R's hh

    foreach num of numlist 1/10 {
        
        tab adult_biokid`num' liveswR_biokid`num', m
        
        gen adultbiokid`num'_liveswR = (adult_biokid`num'==1 & liveswR_biokid`num'==1) if (adult_biokid`num'!=. & liveswR_biokid`num'!=.)
        tab adultbiokid`num'_liveswR,m 
        
        if `num'>8 continue //R is only asked about 8 non-bio kids 
        
        tab adult_nonbiokid`num' liveswR_nonbiokid`num', m
        
        gen adultnonbiokid`num'_liveswR = (adult_nonbiokid`num'==1 & liveswR_nonbiokid`num'==1) if (adult_nonbiokid`num'!=. & liveswR_nonbiokid`num'!=.)
        tab adultnonbiokid`num'_liveswR,m 
        
    }

    //Step 3: sum the dummies created in previous step to get # of R's bio kids and non-bio kids who are 18+ and live with R
        
        egen R_totadultbiokids_livinginhh = rowtotal(adultbiokid*), missing 
        replace R_totadultbiokids_livinginhh =0 if R_totadultbiokids_livinginhh==. & (v235==0 | v235==5)
        tab R_totadultbiokids_livinginhh, m
        
        egen R_totadultnonbiokids_livinginhh = rowtotal(adultnonbiokid*), missing
        replace R_totadultnonbiokids_livinginhh =0 if R_totadultnonbiokids_livinginhh==. & (v270==0 | v270==5)
        tab R_totadultnonbiokids_livinginhh, m
        
        
    gen R_totnumkids_18plus_livinginhh = R_totadultbiokids_livinginhh + R_totadultnonbiokids_livinginhh if R_totadultnonbiokids_livinginhh!=. 
    replace R_totnumkids_18plus_livinginhh = R_totadultbiokids_livinginhh if R_totadultnonbiokids_livinginhh==.
    tab R_totnumkids_18plus_livinginhh, m
    
    //Step 4: add together # of children 0-17 living in R's hh and # of children 18+ living in R's hh
    gen R_totnumkids_livinginhh = R_totnumkids_0to17_livinginhh + R_totnumkids_18plus_livinginhh if R_totnumkids_0to17_livinginhh!=. //only R_totnumkids_0to17_livinginhh has missings
    replace R_totnumkids_livinginhh = R_totnumkids_18plus_livinginhh if R_totnumkids_0to17_livinginhh==.
    tab R_totnumkids_livinginhh,m 
    label var R_totnumkids_livinginhh "Total # of kids (of any age) living in R's hh"
        
********************************
********************************

*total # of people living in R's household
    ren v780 R_hhsize_plusR //seems like R is included in v780 (total # of persons (adults and children) in household)
    tab R_hhsize_plusR,m 
    
    gen R_hhsize_minusR = R_hhsize_plusR -1
    tab R_hhsize_minusR,m 
    
    label var R_hhsize_plusR "total # of persons in R's hh (including R)"
    label var R_hhsize_minusR "total # of persons in R's hh (NOT including R)"      
    